﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using FineUI;

namespace lcmyjobs.Web.enprise
{
    public partial class interview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //this.Title = string.Format("个人管理中心—我的工作：职位收藏夹   {0}", Application["webname"].ToString());
                if (Session["AskInterview"] != null)
                {
                    lcmyjobs.Model.enterprise_interview ei = Session["AskInterview"] as lcmyjobs.Model.enterprise_interview;

                    this.hid_bid.Value = ei.enterprise_bid.Value.ToString();
                    this.hid_uid.Value = ei.uid.Value.ToString();

                    DataSet ds = new lcmyjobs.BLL.enterprise_basic().GetReleaseJobByBid(ei.enterprise_bid.Value);

                    this.ddl_rid.DataSource = ds.Tables[3];
                    this.ddl_rid.DataValueField = "enterprise_rid";
                    this.ddl_rid.DataTextField = "jobs_name";

                    this.ddl_rid.DataBind();

                    if (ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0]["interviewadd"] != null)
                    {
                        this.txt_addr.Text = ds.Tables[0].Rows[0]["interviewadd"].ToString();
                    }


                    this.txt_min.Text = "0";
                    ddltime();
                }
                //btnCancle.OnClientClick = ActiveWindow.GetHideReference();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            int enterprise_bid = int.Parse(this.hid_bid.Value);
            int enterprise_rid = int.Parse(this.ddl_rid.SelectedItem.Value);
            int uid = int.Parse(this.hid_uid.Value);
            //DateTime interviewtime = DateTime.Parse(this.txtinterviewtime.Text);
            string inputtime = this.txt_month.Text + "/" + this.txt_day.Text + "/" + this.txt_year.Text + " " + this.txt_hour.Text + ":" + this.txt_min.Text + ":00";
            DateTime interviewtime = DateTime.Parse(inputtime);
            string interviewexp = this.txtinterviewexp.Text;
            bool isuserbrower = false;
            bool issuccess = false;
            bool iscome = false;
            DateTime toldtime = DateTime.Now;

            lcmyjobs.Model.enterprise_interview model = new lcmyjobs.Model.enterprise_interview();
            model.enterprise_bid = enterprise_bid;
            model.enterprise_rid = enterprise_rid;
            model.uid = uid;
            model.interviewtime = interviewtime;
            model.interviewexp = interviewexp;
            model.isuserbrower = isuserbrower;
            model.issuccess = issuccess;
            model.iscome = iscome;
            model.toldtime = toldtime;
            model.invite_addr = this.txt_addr.Text; //add by liuhui

            lcmyjobs.BLL.enterprise_interview bll = new lcmyjobs.BLL.enterprise_interview();
            if (bll.Add(model) > 0)
            {
                //Maticsoft.Common.MessageBox.ResponseScript(this,"alert('邀请面试成功！');this.close();");
                //Maticsoft.Common.MessageBox.ShowAndRedirect(this, "邀请面试成功！", "../users/show_user-"+uid+".html");

                //PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
                Alert.Show("邀请面试成功！","",ActiveWindow.GetHideRefreshReference());
                
                //Alert.Show(

            }

        }

        protected void btnCancle_Click(object sender, EventArgs e)
        {
            //Maticsoft.Common.MessageBox.ResponseScript(this, "this.close();");
            //int uid = int.Parse(this.hid_uid.Value);
            //Response.Redirect("../users/show_user-"+uid+".html");
            //string str = ActiveWindow.GetHideReference();
            PageContext.RegisterStartupScript(ActiveWindow.GetHideReference());
        }

        private void ddltime()
        {
            //string year = DateTime.Today.Year.ToString();


            DateTime tnow = DateTime.Now;//现在时间
            ArrayList AlYear = new ArrayList();
            int thisyeat = int.Parse(DateTime.Today.Year.ToString());

            int i = 0;
            for (i = 0; i <= 1; i++)
            {
                // 面试时间，“年”的设定，只能为今年明年
                AlYear.Add(thisyeat + i);
            }
            ArrayList AlMonth = new ArrayList();
            for (i = 1; i <= 12; i++)
                AlMonth.Add(i);
            if (!this.IsPostBack)
            {
                txt_year.DataSource = AlYear;
                txt_year.DataBind();//绑定年
                //选择当前年
                txt_year.SelectedValue = tnow.Year.ToString();
                txt_month.DataSource = AlMonth;
                txt_month.DataBind();//绑定月
                //选择当前月
                txt_month.SelectedValue = tnow.Month.ToString();
                int year, month;
                year = Int32.Parse(txt_year.SelectedValue);
                month = Int32.Parse(txt_month.SelectedValue);
                BindDays(year, month);//绑定天
                //选择当前日期
                txt_day.SelectedValue = tnow.Day.ToString();
            }
        }

        //判断闰年
        private bool CheckLeap(int year)
        {
            if (((year % 4) == 0) && ((year % 100) != 0) || (year % 400 == 0))
                return true;
            else
                return false;
        }
        //绑定每月的天数
        private void BindDays(int year, int month)
        {
            int i;
            ArrayList AlDay = new ArrayList();

            switch (month)
            {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    for (i = 1; i <= 31; i++)
                        AlDay.Add(i);
                    break;
                case 2:
                    if (CheckLeap(year))
                    {
                        for (i = 1; i <= 29; i++)
                            AlDay.Add(i);
                    }
                    else
                    {
                        for (i = 1; i <= 28; i++)
                            AlDay.Add(i);
                    }
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    for (i = 1; i <= 30; i++)
                        AlDay.Add(i);
                    break;
            }
            txt_day.DataSource = AlDay;
            txt_day.DataBind();
        }



        //选择年
        protected void ddl_year_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            int year, month;
            year = Int32.Parse(txt_year.SelectedValue);
            month = Int32.Parse(txt_month.SelectedValue);
            BindDays(year, month);
        }
        //选择月
        protected void ddl_month_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            int year, month;
            year = Int32.Parse(txt_year.SelectedValue);
            month = Int32.Parse(txt_month.SelectedValue);
            BindDays(year, month);
        }



    }
}